package com.cloud.music.utils;

import java.util.Objects;

public class CookieUtil {

    /**
     * 保存cookie
     */
    private static final ThreadLocal<String> COOKIE_STORE = new ThreadLocal<>();

    /**
     * 设置cookie
     * @param cookie cookie
     */
    public static void setCurrentCookie(String cookie) {
        COOKIE_STORE.set(cookie);
    }

    /**
     * 获取cookie
     * @return cookie
     */
    public static String getCurrentCookie() {
        String cookie = COOKIE_STORE.get();
        if (Objects.isNull(cookie)) {
            setCurrentCookie("");
        }
        return COOKIE_STORE.get();
    }

    /**
     * 清除cookie
     */
    public static void remove() {
        COOKIE_STORE.remove();
    }
}
